package com.zly.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.zly.entity.User;
import com.zly.service.DormService;
import com.zly.service.impl.DormServiceImpl;

public class UpdateAction extends ActionSupport {

	/**
	 * 反序列化
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 修改密码
	 * 
	 * @return
	 */
	public String updatePwd() {
		// 用request获取值
		HttpServletRequest request = ServletActionContext.getRequest();
		String uname = request.getParameter("uname");
		String upwd = request.getParameter("upwd");
		//先调用service层查询当前用户名的信息
		DormService<User> dormService = new DormServiceImpl<>();
		List<User> users = dormService.select(User.class, "select * from user where uname = '"+uname+"'");
		User user = new User(users.get(0).getUid(), uname, upwd, users.get(0).getUpost());
		System.out.println(user);
		dormService.update(user);
		return SUCCESS;
	}
}
